﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Utility;
using Utility.Json;
using System.Data;
using Utility.Comm;
using Utility.Helper;
using MsgCenter.Web.Handlers;

namespace MsgCenter.Web
{
    /// <summary>
    /// WS_Message 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class WS_Message : System.Web.Services.WebService
    {
        #region 调用客户端IP地址
        /// <summary>
        /// 调用客户端IP地址
        /// </summary>
        /// <returns></returns>
        private string GetIP()
        {
            string ip = "";
            try
            {
                if (Context.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
                }
            }
            catch
            { }
            return ip;
        }
        #endregion


        [WebMethod(Description = @"发送消息内容(
            strMessageID:消息ID<br>
            strApplicationCode：应用程序Code<br>
            strMessage：消息内容(数组，根据strTempletNo后台模板来定义发送的数组)<br>
            strTempletNo：后台模板编号<br>
            strReceiveLoginName：接收信息人的登陆帐号<br>
            <br>
            <br>
            <br>

            返回结果：JsonRetData实体的Json格式{'State':'true或false', 'Messag':'错误消息内容', 'RetCode':'','RetData':'' }
        )")]
        public string WS_SendMessge(string strMessageID, string strApplicationCode, string strTempletNo, string[] strMessage, string strReceiveLoginName)
        {
            if (strMessageID.IsNullOrEmpty())
            {
                strMessageID = "接口(asmx)发送" + DateTime.Now.DateTimeToyyyyMMddHHmmss();
            }
            return WS_Send.WS_SendMessge(strMessageID, strApplicationCode, strTempletNo, strMessage, strReceiveLoginName, GetIP()).AssemblyJson();
        }

        [WebMethod(Description = @"发送消息内容【手机号码】(
            strMessageID:消息ID<br>
            strApplicationCode：应用程序Code<br>
            strMessage：消息内容(数组，根据strTempletNo后台模板来定义发送的数组)<br>
            strTempletNo：后台模板编号<br>
            strMobile：接收信息人的手机号码<br>
            <br>
            返回结果：JsonRetData实体的Json格式{'State':'true或false', 'Messag':'错误消息内容', 'RetCode':'','RetData':'' }
            <br>
            <br>
        )")]
        public string WS_SendMessge_Mobile(string strMessageID, string strApplicationCode, string strTempletNo, string[] strMessage, string strMobile)
        {
            if (strMessageID.IsNullOrEmpty())
            {
                strMessageID = "接口(asmx)发送" + DateTime.Now.DateTimeToyyyyMMddHHmmss();
            }
            return WS_Send.WS_SendMessge_Mobile(strMessageID, strApplicationCode, strTempletNo, strMessage, GetIP(), strMobile).AssemblyJson();
        }


        [WebMethod(Description = @"发送消息内容手机号码、角色名称(
            strMessageID:消息ID<br>
            strApplicationCode：应用程序Code<br>
            strTempletNo：后台模板编号<br>
            strMessage：消息内容(数组，根据strTempletNo后台模板来定义发送的数组)<br>
            strMobile：接收信息人的手机号码<br>
            <br>
            返回结果：JsonRetData实体的Json格式{'State':'true或false', 'Messag':'错误消息内容', 'RetCode':'','RetData':'' }
            <br>
            <br>
        )")]
        public string WS_SendMessge_Role(string strMessageID, string strApplicationCode, string strTempletNo, string[] strMessage, string strMobile)
        {
            if (strMessageID.IsNullOrEmpty())
            {
                strMessageID = "接口(asmx)发送" + DateTime.Now.DateTimeToyyyyMMddHHmmss();
            }
            return WS_Send.WS_SendMessge_Role(strMessageID, strApplicationCode, strTempletNo, strMessage, GetIP(), strMobile).AssemblyJson();
        }
    }
}
